{{define "sidebar"}}
<div class="flex flex-col h-full">
    <!-- Logo -->
    <div class="flex items-center justify-center h-16 bg-blue-600 text-white">
        <div class="flex items-center">
            <svg class="w-8 h-8 mr-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z"></path>
            </svg>
            <span class="text-xl font-bold">Simple CRM</span>
        </div>
    </div>

    <!-- Navigation -->
    <nav class="flex-1 px-4 py-6 space-y-2 overflow-y-auto">
        <!-- Dashboard -->
        <a href="/dashboard" 
           class="flex items-center px-4 py-3 text-gray-700 rounded-lg hover:bg-blue-50 hover:text-blue-600 transition-colors duration-200 {{if eq .CurrentPage "dashboard"}}bg-blue-50 text-blue-600 border-r-2 border-blue-600{{end}}">
            <svg class="w-5 h-5 mr-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2H5a2 2 0 00-2-2z"></path>
                <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 5a2 2 0 012-2h4a2 2 0 012 2v6H8V5z"></path>
            </svg>
            <span>仪表盘</span>
        </a>

        <!-- Customer Management -->
        <div x-data="{ open: {{if or (eq .CurrentPage "customers") (eq .CurrentPage "customer-detail") (eq .CurrentPage "customer-create") (eq .CurrentPage "customer-edit")}}true{{else}}false{{end}} }">
            <button @click="open = !open" 
                    class="w-full flex items-center justify-between px-4 py-3 text-gray-700 rounded-lg hover:bg-gray-50 transition-colors duration-200 {{if or (eq .CurrentPage "customers") (eq .CurrentPage "customer-detail") (eq .CurrentPage "customer-create") (eq .CurrentPage "customer-edit")}}bg-blue-50 text-blue-600{{end}}">
                <div class="flex items-center">
                    <svg class="w-5 h-5 mr-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4.354a4 4 0 110 5.292M15 21H3v-1a6 6 0 0112 0v1zm0 0h6v-1a6 6 0 00-9-5.197m13.5-9a2.5 2.5 0 11-5 0 2.5 2.5 0 015 0z"></path>
                    </svg>
                    <span>客户管理</span>
                </div>
                <svg class="w-4 h-4 transform transition-transform duration-200" :class="open ? 'rotate-180' : ''" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"></path>
                </svg>
            </button>
            <div x-show="open" x-transition class="ml-8 mt-2 space-y-1">
                <a href="/customers" 
                   class="flex items-center px-4 py-2 text-sm text-gray-600 rounded-lg hover:bg-gray-50 hover:text-gray-900 {{if eq .CurrentPage "customers"}}bg-gray-100 text-gray-900{{end}}">
                    <svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5H7a2 2 0 00-2 2v10a2 2 0 002 2h8a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path>
                    </svg>
                    <span>客户列表</span>
                </a>
                <a href="/customers/new" 
                   class="flex items-center px-4 py-2 text-sm text-gray-600 rounded-lg hover:bg-gray-50 hover:text-gray-900 {{if eq .CurrentPage "customer-create"}}bg-gray-100 text-gray-900{{end}}">
                    <svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6"></path>
                    </svg>
                    <span>添加客户</span>
                </a>
            </div>
        </div>

        <!-- Partner Management -->
        <div x-data="{ open: {{if or (eq .CurrentPage "partners") (eq .CurrentPage "partner-detail") (eq .CurrentPage "partner-create") (eq .CurrentPage "partner-edit")}}true{{else}}false{{end}} }">
            <button @click="open = !open" 
                    class="w-full flex items-center justify-between px-4 py-3 text-gray-700 rounded-lg hover:bg-gray-50 transition-colors duration-200 {{if or (eq .CurrentPage "partners") (eq .CurrentPage "partner-detail") (eq .CurrentPage "partner-create") (eq .CurrentPage "partner-edit")}}bg-blue-50 text-blue-600{{end}}">
                <div class="flex items-center">
                    <svg class="w-5 h-5 mr-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 21V5a2 2 0 00-2-2H7a2 2 0 00-2 2v16m14 0h2m-2 0h-5m-9 0H3m2 0h5M9 7h1m-1 4h1m4-4h1m-1 4h1m-5 10v-5a1 1 0 011-1h2a1 1 0 011 1v5m-4 0h4"></path>
                    </svg>
                    <span>合作机构</span>
                </div>
                <svg class="w-4 h-4 transform transition-transform duration-200" :class="open ? 'rotate-180' : ''" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"></path>
                </svg>
            </button>
            <div x-show="open" x-transition class="ml-8 mt-2 space-y-1">
                <a href="/partners" 
                   class="flex items-center px-4 py-2 text-sm text-gray-600 rounded-lg hover:bg-gray-50 hover:text-gray-900 {{if eq .CurrentPage "partners"}}bg-gray-100 text-gray-900{{end}}">
                    <svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5H7a2 2 0 00-2 2v10a2 2 0 002 2h8a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2"></path>
                    </svg>
                    <span>机构列表</span>
                </a>
                <a href="/partners/new" 
                   class="flex items-center px-4 py-2 text-sm text-gray-600 rounded-lg hover:bg-gray-50 hover:text-gray-900 {{if eq .CurrentPage "partner-create"}}bg-gray-100 text-gray-900{{end}}">
                    <svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 6v6m0 0v6m0-6h6m-6 0H6"></path>
                    </svg>
                    <span>添加机构</span>
                </a>
            </div>
        </div>

        <!-- Push Management -->
        <div x-data="{ open: {{if or (eq .CurrentPage "push") (eq .CurrentPage "push-manual") (eq .CurrentPage "push-records") (eq .CurrentPage "push-stats")}}true{{else}}false{{end}} }">
            <button @click="open = !open" 
                    class="w-full flex items-center justify-between px-4 py-3 text-gray-700 rounded-lg hover:bg-gray-50 transition-colors duration-200 {{if or (eq .CurrentPage "push") (eq .CurrentPage "push-manual") (eq .CurrentPage "push-records") (eq .CurrentPage "push-stats")}}bg-blue-50 text-blue-600{{end}}">
                <div class="flex items-center">
                    <svg class="w-5 h-5 mr-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 19l9 2-9-18-9 18 9-2zm0 0v-8"></path>
                    </svg>
                    <span>推送管理</span>
                </div>
                <svg class="w-4 h-4 transform transition-transform duration-200" :class="open ? 'rotate-180' : ''" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"></path>
                </svg>
            </button>
            <div x-show="open" x-transition class="ml-8 mt-2 space-y-1">

                <a href="/push/manual" 
                   class="flex items-center px-4 py-2 text-sm text-gray-600 rounded-lg hover:bg-gray-50 hover:text-gray-900 {{if eq .CurrentPage "push-manual"}}bg-gray-100 text-gray-900{{end}}">
                    <svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 15l-2 5L9 9l11 4-5 2zm0 0l5 5M7.188 2.239l.777 2.897M5.136 7.965l-2.898-.777M13.95 4.05l-2.122 2.122m-5.657 5.656l-2.12 2.122"></path>
                    </svg>
                    <span>手动推送</span>
                </a>

                <a href="/push/records" 
                   class="flex items-center px-4 py-2 text-sm text-gray-600 rounded-lg hover:bg-gray-50 hover:text-gray-900 {{if eq .CurrentPage "push-records"}}bg-gray-100 text-gray-900{{end}}">
                    <svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z"></path>
                    </svg>
                    <span>推送记录</span>
                </a>
                <a href="/push/stats" 
                   class="flex items-center px-4 py-2 text-sm text-gray-600 rounded-lg hover:bg-gray-50 hover:text-gray-900 {{if eq .CurrentPage "push-stats"}}bg-gray-100 text-gray-900{{end}}">
                    <svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 19v-6a2 2 0 00-2-2H5a2 2 0 00-2 2v6a2 2 0 002 2h2a2 2 0 002-2zm0 0V9a2 2 0 012-2h2a2 2 0 012 2v10m-6 0a2 2 0 002 2h2a2 2 0 002-2m0 0V5a2 2 0 012-2h2a2 2 0 012 2v14a2 2 0 01-2 2h-2a2 2 0 01-2-2z"></path>
                    </svg>
                    <span>推送统计</span>
                </a>
            </div>
        </div>

        <!-- System Management -->
        <div x-data="{ open: {{if or (eq .CurrentPage "users") (eq .CurrentPage "user-create") (eq .CurrentPage "user-edit") (eq .CurrentPage "user-detail") (eq .CurrentPage "roles") (eq .CurrentPage "role-create") (eq .CurrentPage "role-edit") (eq .CurrentPage "role-detail") (eq .CurrentPage "permissions") (eq .CurrentPage "permission-create") (eq .CurrentPage "permission-edit") (eq .CurrentPage "permission-detail") (eq .CurrentPage "logs")}}true{{else}}false{{end}} }">
            <button @click="open = !open" 
                    class="w-full flex items-center justify-between px-4 py-3 text-gray-700 rounded-lg hover:bg-gray-50 transition-colors duration-200 {{if or (eq .CurrentPage "users") (eq .CurrentPage "user-create") (eq .CurrentPage "user-edit") (eq .CurrentPage "user-detail") (eq .CurrentPage "roles") (eq .CurrentPage "role-create") (eq .CurrentPage "role-edit") (eq .CurrentPage "role-detail") (eq .CurrentPage "permissions") (eq .CurrentPage "permission-create") (eq .CurrentPage "permission-edit") (eq .CurrentPage "permission-detail") (eq .CurrentPage "logs")}}bg-blue-50 text-blue-600{{end}}">
                <div class="flex items-center">
                    <svg class="w-5 h-5 mr-3" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10.325 4.317c.426-1.756 2.924-1.756 3.35 0a1.724 1.724 0 002.573 1.066c1.543-.94 3.31.826 2.37 2.37a1.724 1.724 0 001.065 2.572c1.756.426 1.756 2.924 0 3.35a1.724 1.724 0 00-1.066 2.573c.94 1.543-.826 3.31-2.37 2.37a1.724 1.724 0 00-2.572 1.065c-.426 1.756-2.924 1.756-3.35 0a1.724 1.724 0 00-2.573-1.066c-1.543.94-3.31-.826-2.37-2.37a1.724 1.724 0 00-1.065-2.572c-1.756-.426-1.756-2.924 0-3.35a1.724 1.724 0 001.066-2.573c-.94-1.543.826-3.31 2.37-2.37.996.608 2.296.07 2.572-1.065z"></path>
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 12a3 3 0 11-6 0 3 3 0 016 0z"></path>
                    </svg>
                    <span>系统管理</span>
                </div>
                <svg class="w-4 h-4 transform transition-transform duration-200" :class="open ? 'rotate-180' : ''" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"></path>
                </svg>
            </button>
            <div x-show="open" x-transition class="ml-8 mt-2 space-y-1">
                <a href="/system/users" 
                   class="flex items-center px-4 py-2 text-sm text-gray-600 rounded-lg hover:bg-gray-50 hover:text-gray-900 {{if or (eq .CurrentPage "users") (eq .CurrentPage "user-create") (eq .CurrentPage "user-edit") (eq .CurrentPage "user-detail")}}bg-gray-100 text-gray-900{{end}}">
                    <svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M16 7a4 4 0 11-8 0 4 4 0 018 0zM12 14a7 7 0 00-7 7h14a7 7 0 00-7-7z"></path>
                    </svg>
                    <span>用户管理</span>
                </a>
                <a href="/system/roles" 
                   class="flex items-center px-4 py-2 text-sm text-gray-600 rounded-lg hover:bg-gray-50 hover:text-gray-900 {{if or (eq .CurrentPage "roles") (eq .CurrentPage "role-create") (eq .CurrentPage "role-edit") (eq .CurrentPage "role-detail")}}bg-gray-100 text-gray-900{{end}}">
                    <svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 20h5v-2a3 3 0 00-5.356-1.857M17 20H7m10 0v-2c0-.656-.126-1.283-.356-1.857M7 20H2v-2a3 3 0 015.356-1.857M7 20v-2c0-.656.126-1.283.356-1.857m0 0a5.002 5.002 0 019.288 0M15 7a3 3 0 11-6 0 3 3 0 016 0zm6 3a2 2 0 11-4 0 2 2 0 014 0zM7 10a2 2 0 11-4 0 2 2 0 014 0z"></path>
                    </svg>
                    <span>角色管理</span>
                </a>
                <a href="/system/permissions" 
                   class="flex items-center px-4 py-2 text-sm text-gray-600 rounded-lg hover:bg-gray-50 hover:text-gray-900 {{if or (eq .CurrentPage "permissions") (eq .CurrentPage "permission-create") (eq .CurrentPage "permission-edit") (eq .CurrentPage "permission-detail")}}bg-gray-100 text-gray-900{{end}}">
                    <svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z"></path>
                    </svg>
                    <span>权限管理</span>
                </a>
                <a href="/system/logs" 
                   class="flex items-center px-4 py-2 text-sm text-gray-600 rounded-lg hover:bg-gray-50 hover:text-gray-900 {{if eq .CurrentPage "logs"}}bg-gray-100 text-gray-900{{end}}">
                    <svg class="w-4 h-4 mr-2" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                        <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"></path>
                    </svg>
                    <span>操作日志</span>
                </a>
            </div>
        </div>
    </nav>

    <!-- User Info -->
    <div class="px-4 py-4 border-t border-gray-200">
        <div x-data="{ open: false }" class="relative">
            <button @click="open = !open" 
                    class="w-full flex items-center px-4 py-3 text-gray-700 rounded-lg hover:bg-gray-50 transition-colors duration-200">
                <div class="w-8 h-8 bg-blue-500 rounded-full flex items-center justify-center text-white text-sm font-medium mr-3">
                    {{if .User}}{{substr .User.RealName 0 1}}{{else}}U{{end}}
                </div>
                <div class="flex-1 text-left">
                    <div class="text-sm font-medium">{{if .User}}{{.User.RealName}}{{else}}用户{{end}}</div>
                    <div class="text-xs text-gray-500">{{if .User}}{{.User.Username}}{{else}}username{{end}}</div>
                </div>
                <svg class="w-4 h-4 transform transition-transform duration-200" :class="open ? 'rotate-180' : ''" fill="none" stroke="currentColor" viewBox="0 0 24 24">
                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 15l7-7 7 7"></path>
                </svg>
            </button>
            
            <div x-show="open" 
                 x-transition:enter="transition ease-out duration-200"
                 x-transition:enter-start="opacity-0 transform scale-95"
                 x-transition:enter-end="opacity-100 transform scale-100"
                 x-transition:leave="transition ease-in duration-75"
                 x-transition:leave-start="opacity-100 transform scale-100"
                 x-transition:leave-end="opacity-0 transform scale-95"
                 class="absolute bottom-full left-0 right-0 mb-2 bg-white rounded-lg shadow-lg border border-gray-200 py-2">
                <a href="/profile" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-50">
                    <i class="iconfont icon-user mr-2"></i>
                    个人资料
                </a>
                <a href="/settings" class="block px-4 py-2 text-sm text-gray-700 hover:bg-gray-50">
                    <i class="iconfont icon-setting mr-2"></i>
                    账户设置
                </a>
                <hr class="my-1">
                <button @click="$root.logout()" class="w-full text-left px-4 py-2 text-sm text-red-600 hover:bg-red-50">
                    <i class="iconfont icon-logout mr-2"></i>
                    退出登录
                </button>
            </div>
        </div>
    </div>
</div>
{{end}}